package org.hilo.boot.core.shiro;

import java.io.PrintStream;
import java.io.PrintWriter;

import org.apache.shiro.session.InvalidSessionException;
import org.jretty.util.NestedException;
import org.jretty.util.support.ExceptionDelegateSupport;
import org.jretty.util.support.NestedExceptionDelegate;

/**
 * 自定义UnknownSessionException，用于省略堆栈信息
 * 
 * @author zollty
 * @since 2018年9月3日
 */
public class UnknownSessionException extends InvalidSessionException 
    implements NestedException, ExceptionDelegateSupport {
    
    private static final long serialVersionUID = 7246460157526737441L;
    
    private final NestedExceptionDelegate delegate;
    
    public static final String EXCEPTION_PRIFIX = "org.shiro.UnknownSessionException: ";

    /**
     * @param message 自定义错误信息
     * @param args 占位符参数--[ 变长参数，用于替换message字符串里面的占位符"{}" ]
     */
    public UnknownSessionException(Object message, Object... args) {
        this.delegate = new NestedExceptionDelegate(EXCEPTION_PRIFIX, message, args);
    }
    
    @Override
    public void printStackTrace () {
    }
    
    @Override
    public void printStackTrace(PrintWriter err) {
    }
    
    @Override
    public void printStackTrace (PrintStream err) {
    }
    
    @Override
    public StackTraceElement[] getStackTrace() {
        return new StackTraceElement[0];
    }
    
    @Override
    public String getStackTraceStr() {
        return delegate.getStackTraceStr(null);
    }
    
    @Override
    public String getMessage() {
        return delegate.getMessage();
    }
    
    @Override
    public String toString() {
        return delegate.toString();
    }

    @Override
    public NestedExceptionDelegate getDelegate() {
        return delegate;
    }

    /**
     * 获取最原始的那个异常对象，Nested Exception API 默认屏蔽掉此函数的结果
     * 如果要获取原始异常，请调用 {@link #getOrigException()}
     */
    @Override
    public Throwable getCause() {
        return null;
    }

    @Override
    public Throwable getOrigException() {
        return delegate.getOrigException();
    }

}
